//
//  ServerHepler.m
//  HandyQR
//
//  Created by cry on 2017/8/29.
//  Copyright © 2017年 cry. All rights reserved.
//

#import "ServerHepler.h"
#import "ShowQRWindowController.h"

@implementation ServerHepler
{
    ShowQRWindowController *_windowCtr;
}

- (void)generateQR:(NSPasteboard *)pboard
          userData:(NSString *)data
             error:(NSString **)error{
    
    NSArray *classes = [NSArray arrayWithObject:[NSString class]];
    NSDictionary *options = [NSDictionary dictionary];
    if (![pboard canReadObjectForClasses:classes options:options]) {
        return;
    }
    NSString *pboardString = [pboard stringForType:NSPasteboardTypeString];
    [self showQRWithString:pboardString];
    [pboard clearContents];
}

- (void)showQRWithString:(NSString *)string{
    
    [[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
    _windowCtr = [[ShowQRWindowController alloc] initWithWindowNibName:@"ShowQRWindowController"];
    _windowCtr.qrString = string;
    [_windowCtr.window center];
    [_windowCtr.window orderFront:self];
}

@end
